@echo off

setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

REM ======================================================================

REM environment settings
set wc=D:\zerox\mobile\Nokia\sign2\
set cert=%wc%dospy.cer
set key=%wc%dospy.key
set signsis_exe=%wc%signsis.exe

REM check environment
if not exist !cert! call :err_no_file !cert! && exit /b -1
if not exist !key! call :err_no_file !key! && exit /b -1
if not exist !signsis_exe! call :err_no_file !signsis_exe! && exit /b -1

REM argument
if "%~1" == "-p" set b_pause=1 && shift

if "%~1" == "" goto err_no_arg
set input_sis=%~1

if "%~2" == "" (
    set output_sis=%~n1
    set output_sis=!output_sis:unsign=sign!
    if "!output_sis!"=="%~n1" (set output_sis=%~dpn1_signed.sis) else (set output_sis=%~dp1!output_sis!.sis)
) else (
    set output_sis=%~2
)

echo =================================================
echo * Nokia Symbian Installation File Signing Script
echo *                                 by Xia Zuoling
echo *                                    2008-4-5
echo =================================================
echo.
echo  INPUT: !input_sis!
echo OUTPUT: !output_sis!
echo.
echo CERT: !cert!
echo  KEY: !key!

echo.
!signsis_exe! "!input_sis!" "!output_sis!" "!cert!" "!key!"
echo.

if errorlevel 1 (
    echo ERROR occured when signing.
    REM exit /b -1
) else (
    echo Done, signing success.
)

if defined b_pause pause

goto :eof

REM ======================================================================

:err_no_arg
echo Usage: %~0 INPUT.SIS [OUTPUT.SIS]
goto :eof

:err_no_file
echo ERROR:
echo   %~1: file not found
echo   Check your 'environment settings'
goto :eof

REM ======================================================================

endlocal
